package com.codeye.office.excel;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class ExcelReadTools extends ExcelBase {
    public static List<String> Read_sm(String finalXlsxPath, boolean isHasTitle, int colNum){  
    	LinkedList<String> rowList = new LinkedList<String>();
        File finalXlsxFile = new File(finalXlsxPath);  		// 读取Excel文档  
        Workbook workBook = null;
		try {
			workBook = getWorkbok(finalXlsxFile);
		} catch (IOException e) {
			e.printStackTrace();
			return rowList;
		}  
        Sheet sheet = workBook.getSheetAt(0);  				// sheet 对应一个工作页  
        
        int rowNumber = sheet.getLastRowNum();  // 第一行从0开始算
        int begLineNum = isHasTitle==true?1:0;
        for (int i = begLineNum; i <= rowNumber; i++) {
        	Row row = sheet.getRow(i);
        	Cell cell = null;
        	try{
        		cell = row.getCell(colNum-1);
        		rowList.add(cell.getStringCellValue());
        	}catch(NullPointerException ex){
        		rowList.add("无数据");
        	}
        }
        return rowList;
    }  

}
